package org.hxyjs.controller;

import org.hxyjs.dto.DTO;
import org.hxyjs.entity.Supplier;
import org.hxyjs.page.PageInfo;
import org.hxyjs.service.SupplierService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@Controller //@Controller注解是用spring容器生成 对象 默认对象名 supplierController
@RequestMapping("/supplierController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /supplierController
public class SupplierController {
	@Resource
    SupplierService supplierService;
	@RequestMapping("/getAllSupplier")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Supplier> getAllSupplier() throws Exception{
    	System.out.println("查询全部供应商");
    	return supplierService.getAllSuppliers();
    }

    @RequestMapping("/deleteSupplierBySuno/{suno}")
	@ResponseBody
    public DTO<Supplier> deleteSupplierBySuno(@RequestBody @PathVariable("suno") String suno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(suno+"删除供应商");
    	return supplierService.deleteSupplierBySuno(suno);
    }

	@RequestMapping("/addSupplierBySuno")
	@ResponseBody
	public DTO<Supplier> addSupplier(@RequestBody Supplier supplier) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加供应商");
		return supplierService.addSupplier(supplier);
	}

	@RequestMapping("/updateSupplierBySuno")
	@ResponseBody
	public DTO<Supplier> updateSupplierBySuno(@RequestBody Supplier supplier) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改供应商成功");
		System.out.println(supplier);
		return supplierService.updateSupplierBySuno(supplier);
	}
	@RequestMapping("/getSupplierBySuno/{suno}")
	@ResponseBody
	public DTO<Supplier> getSupplierBySuno(@PathVariable("suno") String suno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("查询供应商");
		return supplierService.getSupplierBySuno(suno);
	}
	@RequestMapping("/getSupplierByPage")
	@ResponseBody
	public DTO<Supplier> getSupplierByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页查询供应商成功");
		return supplierService.getSupplierByPage(pageInfo);
	}
	@RequestMapping("/selectSupplierWithorderAndUser/{suno}")
	@ResponseBody
	public DTO<Supplier> selectSupplierWithorderAndUser(@PathVariable("suno")String suno) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("查询订单带上用户");
		return supplierService.selectSupplierWithorderAndUser(suno);
	}
}
